package com.techyuan.algorithm.sorts.select;

import com.techyuan.algorithm.utils.PrintUtil;
import com.techyuan.algorithm.utils.SortUtils;
import com.techyuan.algorithm.utils.test.BaseTest;
import com.techyuan.algorithm.utils.test.TestUtils;

/**
 * Created by tianjuntao on 2016/12/12.
 */
public class SelectMain {
    private static int[] data;

    /**
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        int count = 100000000;//12;
        int max = 100000;
        int runCount = 1;
        createSelectDataList(count, max);
        //select(new RanomizedSelect(), count / 2, runCount); //随机选择算法
        select(new BFPRTSelect(), count / 2, runCount);//优化版的随机选择算法
    }

    private static void select(final ISelect select, final int i, final int runCount) {
        TestUtils.testRuntime(new BaseTest() {
            public String test() {
                Integer sInt = select.select(data, i);
                if (runCount < 100)
                    System.out.println(String.format("查找到第%d个数字为：%d", i, sInt));
                return select.getClass().getSimpleName();
            }
        }, runCount);
    }

    public static void createSelectDataList(int count, int max) {
        if (data == null) {
            data = SortUtils.createRandomList(count, max);
            if (data.length < 10000)
                PrintUtil.printArrPretty(data, "查找数组：%s");
        }
        System.out.println("数据生成完成!");
    }
}
